
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>经济管理学院</title>
<link rel="stylesheet" href='css/style.css' type="text/css">

</head>
<script type='text/javascript' src='js/prototype.js'></script>
<script type='text/javascript' src='js/sha1.js'></script>
<script type='text/javascript' src='js/public.js'></script>
<script type="text/javascript">
   var code; 
   var start;
   var stop;
   var shake;
   var grade = " ";
   var userenteryear;
   var userEnterYear1;
   var userEnterYear2;
   var userEnterYear3;
   var userEnterYear4;
   var major;
   var request = {
			QueryString : function(val) {
				var uri = window.location.search;
				var re = new RegExp("" + val + "=([^&?]*)", "ig");
				return ((uri.match(re)) ? (uri.match(re)[0]
						.substr(val.length + 1)) : null);
			}
		};
	function showuserkey() {
		var params = "user_keyName=userName&user_keyName=enterYear&user_keyName=major";
		new Ajax.Request("json/showUser_key", {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				userenteryear=res["result"]["enterYear"];
				if (res["result"]["userName"] == null)
					window.location.href = "login.html";
				document.getElementById("username").innerHTML = "欢迎 "
						+ res["result"]["userName"];
			
				major=res["result"]["major"];
			},
			asynchronous : true
		});
		online();
	}
	function outline() {
		var params = "";
		new Ajax.Request("json/logout", {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();

				window.location.href = "login.html";
			},
			asynchronous : true
		});
	}
	function online() {

		var params = "";
		new Ajax.Request("json/online", {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				document.getElementById("online").innerHTML = "当前在线人数："
						+ res["result"]["online"];
			},
			asynchronous : true
		});
		viewLecturesOutline();
		status();
		createCode();
	}
	function viewLecturesOutline() {
	
		var lectureId = request.QueryString("lectureId");
		var params = "lectureId=" + encodeURIComponent(lectureId);
		new Ajax.Request(
				"json/viewLecturesOutline",
				{
					method : "post",
					parameters : params,
					onComplete : function(request) {
						var res = request.responseText.evalJSON();

						
						if (res["result"]["flag"] == "true") {
							
							if (res["result"]["userEnterYear1"] !== null)
								grade += res["result"]["userEnterYear1"] + " ";
							if (res["result"]["userEnterYear2"] !== null)
								grade += res["result"]["userEnterYear2"] + " ";
							if (res["result"]["userEnterYear3"] !== null)
								grade += res["result"]["userEnterYear3"] + " ";
							if (res["result"]["userEnterYear4"] !== null)
								grade += res["result"]["userEnterYear4"] + " ";
							 start = compareTime(res["result"]["startTime"]);
							 stop = compareTime(res["result"]["stopTime"]);
							 userEnterYear1=res["result"]["userEnterYear1"];
							 userEnterYear2=res["result"]["userEnterYear2"];
							 userEnterYear3=res["result"]["userEnterYear3"];
							 userEnterYear4=res["result"]["userEnterYear4"];
							
                            
							
						
							var str=res["result"]["lecYear"];
							var lecyear1 = str.substr(0,4);
							　　 str = str.replace(lecyear1,'');
						    var lecyear2=str.substr(0,4);
							    str = str.replace(lecyear2,'');
							var lecterm=str.substr(0,1);
							shake=res["result"]["shake"];
							var tmp = "<ul style='width:100%; border-bottom:1px  #999 dotted;'><li style='margin-left:20px;margin-top:20px;'>学期："+lecyear1+"——"+lecyear2+"学年 第"+lecterm+"学期</li><li style='margin-left:20px; '>主题："
							+res["result"]["lecName"]
							+" </li><li style='margin-left:20px;'>主讲人："+res["result"]["lecSpeaker"]
							+"</li><li style='margin-left:20px;'>举办时间："+res["result"]["lecTime"]
							+"</li><li style='margin-left:20px;'>举办地点："+res["result"]["lecPlace"]
							+"</li><li style='margin-left:20px;''>参与年级："+grade
							+"</li><li style='margin-left:20px;'>报名开始时间："+res["result"]["startTime"]
							+"</li><li style='margin-left:20px;'>报名截止时间："+res["result"]["stopTime"]
							+"</li><li style='margin-left:20px;'>发放票数："+res["result"]["lecCodeNumber"]
							+"</li><li style='margin-left:20px;''>备注："+ res["result"]["lecNote"]
						        + "</li><li style='margin-left:20px;'></ul>";
							$("iteratorProductsTarget").innerHTML += tmp;
						}
					},
					asynchronous : false
				});
	}

	
	function RegisterLecture() {
	 
		var lectureId = request.QueryString("lectureId");
		var params = "lectureId=" + lectureId;
		if(start=="大于"){
			alert("请到报名时间之后再报名！");
			
		}
		else if(stop=="小于"){
			alert("报名已经截止");
		}
		else if(userEnterYear1==userenteryear||userEnterYear2==userenteryear||userEnterYear3==userenteryear||userEnterYear4==userenteryear||major=="梁希"){

		new Ajax.Request("json/registerOneLecture", {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();

				if (res["result"]["flag"] == "true") {
					alert("你已成功报名");
					window.location.href = "StuOperateLecture.html?lectureId="
						+lectureId;
				}
			},
			asynchronous : false
		});}
		else{
			alert("该活动适合"+grade+"级学生参加");
		}
	}
	
	
	
	 function createCode()   
	     {    
	       code = "";  
	       var codeLength = 4;
	       var checkCode = document.getElementById("htmlcode2");  
	       var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');//所有候选组成验证码的字符，当然也可以用中文的  
	          
	       for(var i=0;i<codeLength;i++)  
	       {    
	          
	       var charIndex = Math.floor(Math.random()*36);  
	       code +=selectChar[charIndex];          
	         
	       }  
	      
	       if(checkCode)  
	       {  
	        
	         checkCode.value = code;
	       
	       }  
	         
	     } 
	 
	 
	 function status(){
	
				
				var lectureId = request.QueryString("lectureId");
				var params= "lectureId=" + encodeURIComponent(lectureId);
				new Ajax.Request("json/userLectureStatus", {
					method : "post",
					parameters : params,
					onComplete : function(request) {
						var res = request.responseText.evalJSON();
                         
                           var codestatus=res["result"]["status"];
                           var order=res["result"]["order"];
                           if(codestatus=="check")
                        	   {
                        	   var reshtml="<li style='float: left; width: 180px;font-size: 20px; color: red;'>已报名</li><li style='float: left; width: 280px;font-size: 20px; color: red;'>领票序号："+order+"</li>"
                        	   $("registerstatus").innerHTML += reshtml;
                        	   document.getElementById("checkstatustext").innerHTML = "已签到";
                        	   document.getElementById("checkshow1").innerHTML = " ";
                        	   document.getElementById("checkshow2").innerHTML = " ";
                        	   document.getElementById("checkshow3").innerHTML = " ";
           						
                        	   }
                           else if(codestatus=="shake")
                        	   {
                        	   var reshtml="<li style='float: left; width: 180px;font-size: 20px; color: red;'>已报名</li><li style='float: left; width: 280px;font-size: 20px; color: red;'>领票序号："+order+"</li>"
                        	   $("registerstatus").innerHTML += reshtml;
                        	   document.getElementById("checkstatustext").innerHTML = "请领取签到码后及时签到";
                        	   alert('如果发现验证码不能用，请注意小写L、大写i和数字1的区别，如果不能区分请联系团委老师，下一次经管讲坛将不使用易混淆的字母作为签到码');
                        	   }
                           else if(codestatus=="noshake"&shake=="1")
                    	   {
                    	   var reshtml="<li style='float: left; width: 180px;font-size: 20px; color: red;'>已报名</li><li style='float: left; width: 300px;font-size: 20px; color: red;'>未被系统选中，请下次继续报名</li>"
                    	   $("registerstatus").innerHTML += reshtml;
                    	   document.getElementById("checkstatustext").innerHTML = "未签到";
                    	   document.getElementById("checkshow1").innerHTML = " ";
                    	   document.getElementById("checkshow2").innerHTML = " ";
                    	   document.getElementById("checkshow3").innerHTML = " ";
                    	   }
                           else if(codestatus=="noshake"&shake=="0")
                    	   {
                    	   var reshtml="<li style='float: left; width: 180px;font-size: 20px; color: red;'>已报名<input type='button' value='取消报名' onclick='deleteRegisterLecture()'></li><li style='float: left; width: 300px;font-size: 20px; color: red;'>请在报名截止后查看系统分配结果</li>"
                    	   $("registerstatus").innerHTML += reshtml;
                    	   document.getElementById("checkstatustext").innerHTML = "未签到";
                    	   document.getElementById("checkshow1").innerHTML = " ";
                    	   document.getElementById("checkshow2").innerHTML = " ";
                    	   document.getElementById("checkshow3").innerHTML = " ";
                  
                    	   }
                           else if(codestatus=="noregister")
                    	   {
                    	   var reshtml="<li style='float: left; width: 220px;font-size: 20px; color: red;' >未报名<input type='button' value='报名' onclick='RegisterLecture()'></li>"
                    	   $("registerstatus").innerHTML += reshtml;
                    	   document.getElementById("checkstatustext").innerHTML = "请先报名";
                    	   document.getElementById("checkshow1").innerHTML = " ";
                    	   document.getElementById("checkshow2").innerHTML = " ";
                    	   document.getElementById("checkshow3").innerHTML = " ";
                    	   }
						
					},
					asynchronous : false
				});
	 }
	function check() {
	
		var inputCode = document.getElementById("htmlcode1").value;
		var lectureId = request.QueryString("lectureId");
		var checkcode = document.getElementById("checkcode").value;
		if (checkcode == ""||inputCode=="") {
			alert("请输入签到码和验证码！");
			 createCode();
		}
		else if(inputCode != code){
			 alert("验证码输入错误！");
			   createCode();
		}
		else {
			var params = "lectureId=" + encodeURIComponent(lectureId) + "&lecture_registerCode="
					+ encodeURIComponent(checkcode);
         
			new Ajax.Request("json/checkLectureWithCode", {
				method : "post",
				parameters : params,
				onComplete : function(request) {
					var res = request.responseText.evalJSON();
					
					if (res["result"]["flag"] == "true") {
						alert("成功签到");
						window.location.href = "StuOperateLecture.html?lectureId="
							+lectureId;
					}else
						{alert("签到码错误或已被使用！");}
				},
				asynchronous : false
			});
		}
	}
function deleteRegisterLecture(){
	var lectureId = request.QueryString("lectureId");
	var params = "lectureId=" + encodeURIComponent(lectureId);
	if(confirm("确定取消报名？")){
		new Ajax.Request("json/studentDeleteUser_registerLecture", {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					alert("已取消报名");
					window.location.href = "StuOperateLecture.html?lectureId="
						+lectureId;
				}else
					{alert("请在系统分配前取消");}
			},
			asynchronous : false
		});
	}
}
</script>
<body onload="showuserkey()">
	<div id="header">

		<div id="nav">
			<ul
				style="float: left; padding: 0 20px; text-align: center; line-height: 50px;">
				<li style="float: left; font-size: 28px">经管院学术讲坛事务系统</li>
			</ul>
			<ul class="horizon">

				<li class="login">
					<ul class="vertical">
						<li class="userInfo" id="username">&nbsp;你好</li>
						<li class="userInfo2">
							<ul class="horizon">

								<li><a href="editorUser.html" target="_blank"
									style="text-decoration: none;">个人资料</a><br /> <a
									onclick="outline()" style="text-decoration: none;" href="#">注销</a></li>
							</ul>
						</li>
					</ul>
				</li>

			</ul>
		</div>




	</div>
	<div id="main">
		<div
			style="width: 21%; height: 660px; border-right: 3px #660033 solid; float: left; background-color: rgb(242, 247, 252);">
			<div style="margin-top: 50px; ">报名流程：<br>   1、   选择处于报名阶段，且参与年级与你的年级相符的讲座，点击报名。<br>2、由于报名人数一般会大于现场可容纳的人数，所以系统会将入场券随机分配给所有参与报名的同学。<br>3、系统分配后，被选中的同学会获得一个领票序号，在讲座当天入场时，将你的获得的领票序号告诉工作人员，即可获得入场券，出场时凭入场券领取签到码<br>说明：系统分配入场券的时候会根据你以往的报名情况计算你的优先级，以往没被选中优先级会提高，被选中之后优先级会下降，优先级越高越有可能被选中。如果至本学期最后一次讲座仍未被选中，可以向团委老师申请手动报名。</div>
			<div style="margin-top: 20px; ">签到流程：<br>在讲座结束以后领取签到码，登陆系统输入签到码即可</div>
		</div>
		<div style="width: 78%; font-size: 22px; float: right">
			<div style="margin-top: 50px; margin-left: 50px; height: 560px">
				<table width="800" border="0"
					style="font-size: 14px; border: 2px solid #999;">
					<tr>
						<td style="border-bottom: 1px #999 dotted;" id="registerstatus">
							<li
							style="float: left; width: 120px; font-size: 24px; color: red;">报名状态：</li>
                            <li style="float: right;"><a href="StudentIndex.html">返回首页</a></li>



						</td>
					</tr>
					<tr>
						<td id="checkstatus" style="border-bottom: 1px #999 dotted;"><p
								style="font-size: 24px; color: red;">签到状态：</p>
							<li id="checkstatustext"
							style="width: 300px; color: red; font-size: 20px"></li>
							<li id="checkshow1">签到码：<input id="checkcode"></li>
							<li id="checkshow2">验证码：<input id="htmlcode1"><input
								id="htmlcode2" style="width: 60px; background: gray; border: 0;"
								onClick="createCode()" readonly="readonly" /> <a href="#"
								onClick="createCode()">看不清楚</a></li>
							<li id="checkshow3"><input type="button" value="签到"
								onclick="check()"></li></td>
					</tr>
					<tr>
						<td style="font-size: 16px;"><div id="iteratorProductsTarget">

							</div></td>
					</tr>
				</table>


			</div>
			<div style="font-size: 14px; margin-left: 100px;">
				<span id="online">当前在线人数:</span> <span style="margin-left: 150px">Copyright
					&copy; 2013 经济管理学院 北京市海淀区清华东路35号 邮编：100083</span>
			</div>
		</div>

	</div>

</body>
</html>
